package com.onec.service.route.service.impl;

import com.onec.service.api.enums.StatusEnum;
import com.onec.service.api.enums.SystemTypeEnum;
import com.onec.service.route.dao.BlockInfoRepository;
import com.onec.service.route.entity.BlockInfo;
import com.onec.service.route.service.BlockInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author onec
 * @see
 */
@Service
public class BlockInfoServiceImpl implements BlockInfoService {

    @Autowired
    BlockInfoRepository blockInfoRepository;

    @Override
    public boolean isBlockType(String value, SystemTypeEnum systemTypeEnum) {
        BlockInfo blockInfo = blockInfoRepository.findBlockInfoByValueAndType(value, systemTypeEnum);
        if (Optional.ofNullable(blockInfo).isPresent()) {
            if (StatusEnum.isFreeze(blockInfo.getStatus())) {
                return true;
            }
        }
        return false;
    }
}
